import { defineStore } from 'pinia'
import { constantRouterMap } from '@/router/router.config'
import { generatorDynamicRouter } from '@/router/generator-routers'
export const usePermissionStore = defineStore('permission', {
  state() {
    return {
      routers: constantRouterMap,
      addRouters: []
    }
  },
  actions: {
    setRouters(routers) {
      this.addRouters = routers
      this.routers = constantRouterMap.concat(routers)
    },
    async GenerateRoutes () {
      return new Promise((resolve, reject) => {
        generatorDynamicRouter().then(routers => {
          this.setRouters(routers)
          resolve(routers)
        }).catch(e => {
          reject(e)
        })
      })
    }
  },
  persist: {
    enabled: true
  }
})